package com.thering;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;
import java.util.Properties;

/**
 * author: the_ring
 * date: 2022/5/19
 * function: Type Count main
 */
public class TypeCount {

    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        Properties properties = System.getProperties();
        properties.setProperty("HADOOP_USER_NAME", "root");
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://ring1:8020");

        Job job = Job.getInstance(conf);
        job.setJobName("type count");
        job.setJarByClass(TypeCount.class);

        job.setMapperClass(TypeCountMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setReducerClass(TypeCountReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        FileInputFormat.addInputPath(job, new Path("/project/2022-05-24/movies/part-m*"));
        FileOutputFormat.setOutputPath(job, new Path("/project/2022-05-24/type_count/"));

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }


}
